package featuremodel;


import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Vector;

import skyblue.SkyBlueDef;
import skyblue.Variable;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		// *************start of test case 4*****************
		long startTime = System.currentTimeMillis(); 
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	    System.out.println("Start at: "+df.format(new Date())+"\n");
		FeatureModel featuremodel = new FeatureModel();
		Variable a = featuremodel.createFeature("a");
		showAllVariable(featuremodel);
		Variable b1 = featuremodel.createFeature("b1");
		showAllVariable(featuremodel);
		Variable b2 = featuremodel.createFeature("b2");
		showAllVariable(featuremodel);
		Variable c1 = featuremodel.createFeature("c1");
		showAllVariable(featuremodel);
		Variable c2 = featuremodel.createFeature("c2");
		showAllVariable(featuremodel);
		

		Vector<Variable> featuregroup1 = new Vector<Variable>();
		Vector<Variable> featuregroup2 = new Vector<Variable>();
		featuregroup1.add(b2);
		featuregroup2.add(c1);
		featuregroup2.add(c2);
		FeatureGroup fp1 = new FeatureGroup(featuregroup1,FeatureModelDef.PREDICATE_ALL);
		FeatureGroup fp2 = new FeatureGroup(featuregroup2,FeatureModelDef.PREDICATE_SINGLE);
		
		featuremodel.setRoot(a);
		showAllVariable(featuremodel);

		featuremodel.setMandatory(b1, a, SkyBlueDef.WEAK_STRENGTH);
		showAllVariable(featuremodel);

		featuremodel.setOptional(b2, a, SkyBlueDef.MEDIUM_STSTRENGTH);
		showAllVariable(featuremodel);

		featuremodel.addRequireConstraint(b1, b2, SkyBlueDef.MEDIUM_STSTRENGTH);
		showAllVariable(featuremodel);

		featuremodel.addOrConstraint(b2, featuregroup2,
				SkyBlueDef.MEDIUM_STSTRENGTH);
		showAllVariable(featuremodel);
		
//		featuremodel.addOptionalConstraint(c1, b2, SkyBlueDef.MEDIUM_STSTRENGTH);
//		showAllVariable(featuremodel);
//		
//		featuremodel.addOptionalConstraint(c2, b2, SkyBlueDef.MEDIUM_STSTRENGTH);
//		showAllVariable(featuremodel);
//		
//		featuremodel.addRequireCompositeConstraint(fp1, FeatureModelDef.PREDICATE_ALL, fp2, FeatureModelDef.PREDICATE_MULTI, SkyBlueDef.MEDIUM_STSTRENGTH);
//		showAllVariable(featuremodel);
//		

		
		
		featuremodel.addExcludeConstraint(a, b1, SkyBlueDef.MEDIUM_STSTRENGTH);
		showAllVariable(featuremodel);
		
		long endTime = System.currentTimeMillis(); 
		System.out.println("End at: "+df.format(new Date()));
		System.out.println("Time: " + (endTime - startTime) + "ms");

	}

	public static void showAllVariable(FeatureModel featuremodel) {
		FeatureRep fp;
		for (int i = 0; i < featuremodel.getFeatures().size(); i++) {
			fp = (FeatureRep) featuremodel.getFeatures().get(i).getValue()
					.getValuerep();
			System.out.print(fp.getName() + "(" +  featuremodel.getFeatures().get(i).getDeterminedbys().size()+ ")");
			System.out.print("(" + fp.getBindState() + ") ");
		}
		System.out.print("\n\n");
	}

}
